from django.shortcuts import render
from rest_framework.generics import ListAPIView

from goods.models import SKU
from .serializer import SKUSerializer
from rest_framework.filters import OrderingFilter


# Create your views here.


class SKUListView(ListAPIView):
    """商品列表视图"""
    serializer_class = SKUSerializer
    filter_backends = (OrderingFilter,)
    ordering_fields = ('create_time', 'price', 'sales')

    # 排序
    # 分页, 全局设置
    def get_queryset(self):
        category_id = self.kwargs['category_id']
        return SKU.objects.filter(category_id=category_id, is_launched=True)

